package com.lqk.fnandroid.net

import android.util.Log
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory

object RetrofitHelper {
    private const val TAG = "RetrofitHelper"

    private val okhttpClient by lazy {
        OkHttpClient.Builder()
            .addNetworkInterceptor {
                val request = it.request()
                Log.d(TAG, "Http: ${request.url}")
                return@addNetworkInterceptor it.proceed(request)
            }
            .build()
    }
    private val retrofit by lazy {
        Retrofit.Builder()
            .baseUrl("http://192.168.1.38:5001")
            .client(okhttpClient)
            .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }

    fun <T> createService(cls: Class<T>) = retrofit.create(cls)
}